﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

using System.Text.RegularExpressions;
using System.IO;
using System.Reflection;

namespace TestCensoring
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void submitBtn_Click(object sender, RoutedEventArgs e)
        {
            //testing new method ; filter/censor the story first before submitting to database
            const string CensoredText = "[Censored]";
            const string PatternTemplate = @"\b({0})(s?)\b";
            const RegexOptions Options = RegexOptions.IgnoreCase;

            //string[] badWords = new[] { "asser", "asses", "ass" };
            //string[] badWords = File.ReadAllLines("C:\\Users\\AmritUni\\Desktop\\badwords.txt");
            string[] badWords = File.ReadAllLines("C:\\Users\\AmritUni\\Desktop\\badwords.txt");
        
            string input = inputTextBox.Text;
            IEnumerable<Regex> badWordMatchers = badWords.Select(x => new Regex(string.Format(PatternTemplate, x), Options));
            string output = badWordMatchers.Aggregate(input, (current, matcher) => matcher.Replace(current, CensoredText));

            finalStoryTextBox.Text = output;
        }
    }
}
